package com.vidmt.api.common.pojo;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.vidmt.api.common.exceptions.CodeException;

public class ApiResultServer {
	private int code;
	private String msg;
	private Object data;

	public ApiResultServer() {
		this.code = 0;
	}

	public ApiResultServer(Object data) {
		this.code = 0;
		this.data = data;
	}

	public ApiResultServer(CodeException e) {
		this.code = e.getCode();
		this.msg = e.getMessage();
	}

	public ApiResultServer(int code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public void put(String key, Object value) {
		if (data == null) {
			data = new JSONObject();
		}
		JSONObject json = (JSONObject) data;
		json.put(key, value);
	}

	public int getC() {
		return code;
	}

	public void setC(int code) {
		this.code = code;
	}

	public void setM(String msg) {
		this.msg = msg;
	}

	public String getM() {
		return msg;
	}

	public Object getD() {
		return data;
	}

	public void setD(Object data) {
		this.data = data;
	}

	@Override
	public String toString() {
		return JSON.toJSONString(this);
	}
}
